﻿/*
 * 由SharpDevelop创建。
 * 用户： aaa
 * 日期: 2017/2/12
 * 时间: 14:18
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using RabbitMQ.Client;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace rqProducer
{
	class Program
	{
		public static void Main(string[] args)
		{
			 var factory = new ConnectionFactory() { HostName = "localhost" };
        using(var connection = factory.CreateConnection())
        using(var channel = connection.CreateModel())
        {
            channel.QueueDeclare(queue: "task_queue",
                                 durable: true,
                                 exclusive: false,
                                 autoDelete: false,
                                 arguments: null);

            var message = GetMessage(args);
            

            var properties = channel.CreateBasicProperties();
            properties.Persistent = true;
            
            
           while (true) {
            	var date=string.Format(",ID:{0},at:{1}",System.Guid.NewGuid(),DateTime.Now);
            	var body = Encoding.UTF8.GetBytes(message+date);
            	  channel.BasicPublish(exchange: "",
                                 routingKey: "task_queue",
                                 basicProperties: properties,
                                 body: body);
            	Console.WriteLine(" [x] Sent {0}", message+date);
            
            
       
           }
          
        }

        Console.WriteLine(" Press [enter] to exit.");
        Console.ReadLine();
		}
		
		private static string GetMessage(string[] args)
{
    return ((args.Length > 0) ? string.Join(".", args) : "Hello World!");
}
		 
	}
}